package com.meihua.baoleyi.utils;

import android.content.Context;

import com.meihua.baoleyi.common.APIServer;
import com.meihua.baoleyi.common.MyApp;
import com.meihua.baoleyi.net.NetHelper;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.TreeMap;

import okhttp3.Call;
import okhttp3.Response;

/**
 * Created by jzm on 2017/11/10.
 * zm.jin@qq.com
 * 是否设置支付密码
 */

public class IsPayPasswordUtil {

    /**
     * 请求网络 是否设置支付密码
     *
     * @return
     */
    public static void isPayPassword(final Context mContext, final OnIsPayPassword onIsPayPassword) {
        TreeMap<String, String> treeMap = new TreeMap<String, String>();
        treeMap.put("user_id", MyApp.getInstance().getUser_id());
        NetHelper.get(APIServer.ISSETPAYPASSWORD, treeMap, true, new NetHelper.HttpCallBack() {
            @Override
            public void onSuccess(String s, Call call, Response response) {
                JSONObject json;
                try {
                    json = new JSONObject(s);
                    // 是否设置状态码1：未设置，2已设置，若没有此字段则说明请求失败
                    if (json.optString("is_set_pay").equals("2")) { //已设置
                        onIsPayPassword.isSetPayPassword(true);
                    } else {
                        ToastUtil.show(mContext, json.optString("msg"));
                        onIsPayPassword.isSetPayPassword(false);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    public interface OnIsPayPassword {
        void isSetPayPassword(boolean isSet);
    }

}
